package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.domain.Email;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.mapper.EmailMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
import cn.wolfcode.crm.service.IEmailService;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmailServiceImpl implements IEmailService {
    @Autowired
    private EmailMapper emailMapper;

    @Override
    public List<Email> queryLinkman() {
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        return emailMapper.queryLinkman(employee.getId());
    }
    @Override
    public List<Employee> queryColleague() {
        return emailMapper.queryColleague();
    }

    @Override
    public Email queryEmailMessage(Long sourceId,Long id) {
        Email email = emailMapper.queryEmailMessage(sourceId, id);
        emailMapper.changState(sourceId,id);
        return email;
    }

    @Override
    public void sendMessage(Email email) {
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        email.setSourceEmp(employee);
        email.setSendDate(new Date());
        email.setState(true);
        emailMapper.sendMessage(email);
    }

    @Override
    public void deleteMessage(Email email) {
        emailMapper.deleteMessage( email);
    }
}
